<template>
  <div id="user-add-dialog">
    <el-dialog :visible.sync="dialogVisible" width="80%" @closed="clearDialog">
      <span slot="title">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item class="font-weight">管理员</el-breadcrumb-item>
          <el-breadcrumb-item>添加管理员</el-breadcrumb-item>
        </el-breadcrumb>
      </span>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px">
        <el-form-item label="管理员名称:" prop="name">
          <el-col :span="15">
            <el-input v-model="ruleForm.name" placeholder="请输入管理员名称"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="管理员简介:" prop="desc">
          <el-col :span="15">
            <el-input
              type="textarea"
              v-model="ruleForm.desc"
              placeholder="请输入管理员简介,最大不能超过200个字符"
              :rows="5"
              resize="none"
              maxlength="200"
              show-word-limit
            ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      list: {},
      ruleForm: {
        name: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入管理员名称', trigger: 'blur' },
          { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '请填写管理员', trigger: 'blur' },
          { max: 200, message: '管理员不能超过200个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    showDialog(data) {
      this.list = data
      this.dialogVisible = true
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
          this.dialogVisible = false
        } else {
          return false
        }
      })
    },
    clearDialog() {
      this.$nextTick(() => {
        this.$refs.ruleForm.clearValidate()
      })
    }
  }
}
</script>

<style lang="scss">
#user-add-dialog {
  .font-weight {
    font-weight: bold;
  }
}
</style>
